<template>
	<view class="car">

		<view class="container">
			<image src="/static/img/1/27.png" mode="aspectFill" class="i-header"></image>
			<view class="address" @click="add" v-if='addressData.cReceiver != null'>
				<view class="left">
					<view class="name">
						<text>{{addressData.cReceiver}}</text>
						<text>{{addressData.cMobile}}</text>
					</view>
					<view class="addr">{{addressData.cAddress}}</view>
				</view>
				<image src="/static/img/1/93.png" mode="aspectFill"></image>
			</view>
			<view class="address" @click="add" v-if='addressData.cReceiver == null'>
				<view class="left">
					<view class="name">
						<text>请填写收货地址！</text>
					</view>

				</view>
				<image src="/static/img/1/93.png" mode="aspectFill"></image>
			</view>
			<view class="car-list" v-for="(o,index) in detail.orderDetailData" :key='index'>
				<view class="title_name">{{o.shopCustomSetting.cShopTag||"平台自营"}}</view>
				<view class="list-item" v-for="item2 in o.orderDetail" :key="item2.iSKUId">
					<view class="right">
						<view class="goods-img">
							<image :src="item2.DefaultImage" mode="aspectFill"></image>
						</view>
						<view class="info">
							<text class="name">{{item2.cProductName}}</text>
							<text class="price">￥{{item2.fSalePrice}}</text>
							<view class="option">
								<!-- <text class="stock">库存:{{o.lInventoryCount}}</text> -->
								<text class="stock">x {{item2.iQuantity}}</text>
								<!-- <uni-number-box class="step" :min="o.iQuantity" :disabled="true" :max="o.iQuantity" :value="o.iQuantity" :index="index" @eventChange="numberChange"></uni-number-box> -->
							</view>
						</view>

					</view>
				</view>
				<!-- <view class="c-row b-b" style="padding-left: 0;padding-right: 0;"
					@click="showInput(index, o.cClientMemo)">
					<text class="tit">订单备注</text>

					<text class="icon-you">
						<text style="font-size: 23upx;">{{o.cClientMemo}}</text>
						<text class="yticon icon-you"></text>
					</text>
				</view> -->
				<view class="c-row" style="padding-left: 0;padding-right: 0;">
					<text class="tit">订单备注</text>
				</view>
				<view class="c-row b-b" style="padding-left: 0;padding-right: 0; padding-top: 0;">
					<textarea placeholder="请输入备注" placeholder-style="font-size: 12px;" v-model="o.cClientMemo"
						auto-height style="font-size: 12px;" />
				</view>

				<!-- <view class="c-row b-b" style="padding-left: 0;padding-right: 0;" @click="toDeliver"> -->

				<view v-if="detail.oCustomSetting.isMerchantDistribution == 1">
					<view class="c-row b-b" style="padding-left: 0;padding-right: 0;">
						<text class="tit">配送方式</text>

						<text class="icon-you">
							<picker :value="o.number" :range="EMSList" range-key="name" @click="getEms(o)"
								mode="selector" @change="bindEMSChange($event, o)">
								<view class="uni-input">{{o.cDeliverName||'请选择'}}</view>
							</picker>
							<!-- <text style="font-size: 23upx;">{{TheEcho(o.dlyType)}}</text>
						<text class="yticon icon-you"></text> -->
						</text>
					</view>

					<view class="c-row b-b" v-if="o.cDeliverType !== 'EMS'" style="padding-left: 0;padding-right: 0;">
						<text class="tit">门店</text>

						<text class="icon-you">
							<picker :value="o.storeNumber" :range="STOresList" @click="OrderGetStoreListData(o)"
								range-key="name" mode="selector" @change="bindSToreNameChange($event, o)">
								<view class="uni-input">{{o.storeName||"请选择"}}</view>
							</picker>
							<!-- <text style="font-size: 23upx;">{{TheEcho(o.dlyType)}}</text>
						<text class="yticon icon-you"></text> -->
						</text>
					</view>
					<!-- cAppointTime: this.getDate(), // 预约时间段开始时间
				cAppointTime2: this.getDate(), -->
					<view class="c-row b-b" v-if="o.cDeliverType !== 'EMS'&&o.shopCustomSetting.iAppointLimitDays" style="padding-left: 0;padding-right: 0;">
						<text class="tit">提货时间</text>

						<text class="icon-you">
							<picker mode="date" :value="o.dAppointDate" :start="getDates('start')"
								:end="getDates('end',o.shopCustomSetting.iAppointLimitDays)"
								@change="bindDateChange($event, o)">
								<view class="uni-input">{{o.dAppointDate||getDates('start')}}</view>
							</picker>
						</text>
					</view>

					<view class="c-row b-b" v-if="o.cDeliverType !== 'EMS'&&o.shopCustomSetting.iAppointLimitDays" style="padding-left: 0;padding-right: 0;">
						<text class="tit">预约时间段</text>

						<text class="icon-you">
							<picker :value="o.timeNumber" :range="o.shopCustomSetting.appointTime.split(';')"
								mode="selector" @change="bindAppointTime($event, o)">
								<view class="uni-input">{{o.cAppointTime||'请选择'}}</view>
							</picker>
						</text>
					</view>
				</view>

			</view>

			<view class="car-list" v-if="detail.oCustomSetting.isMerchantDistribution == 0">
				<view class="c-row b-b" style="padding-left: 0;padding-right: 0;">
					<text class="tit">配送方式</text>

					<text class="icon-you">
						<picker :value="detail.number" :range="EMSList" range-key="name" @click="getEms(detail)"
							mode="selector" @change="bindEMSChange($event, detail)">
							<view class="uni-input">{{detail.cDeliverName||'请选择'}}</view>
						</picker>
						<!-- <text style="font-size: 23upx;">{{TheEcho(o.dlyType)}}</text>
						<text class="yticon icon-you"></text> -->
					</text>
				</view>

				<view class="c-row b-b" v-if="detail.cDeliverType !== 'EMS'"
					style="padding-left: 0;padding-right: 0;">
					<text class="tit">门店</text>

					<text class="icon-you">
						<picker :value="detail.storeNumber" :range="STOresList" @click="OrderGetStoreListData(detail)"
							range-key="name" mode="selector" @change="bindSToreNameChange($event, detail)">
							<view class="uni-input">{{detail.storeName||"请选择"}}</view>
						</picker>
						<!-- <text style="font-size: 23upx;">{{TheEcho(o.dlyType)}}</text>
						<text class="yticon icon-you"></text> -->
					</text>
				</view>
				<!-- cAppointTime: this.getDate(), // 预约时间段开始时间
				cAppointTime2: this.getDate(), -->
				<view class="c-row b-b" v-if="detail.cDeliverType !== 'EMS'&&detail.oCustomSetting.iAppointLimitDays"
					style="padding-left: 0;padding-right: 0;">
					<text class="tit">提货时间</text>

					<text class="icon-you">
						<picker mode="date" :value="detail.dAppointDate" :start="getDates('start')"
							:end="getDates('end',detail.oCustomSetting.iAppointLimitDays)"
							@change="bindDateChange($event, detail)">
							<view class="uni-input">{{detail.dAppointDate||getDates('start')}}</view>
						</picker>
					</text>
				</view>

				<view class="c-row b-b" v-if="detail.cDeliverType !== 'EMS'&&detail.oCustomSetting.iAppointLimitDays"
					style="padding-left: 0;padding-right: 0;">
					<text class="tit">预约时间段</text>

					<text class="icon-you">
						<picker :value="detail.timeNumber" :range="detail.oCustomSetting.appointTime.split(';')"
							mode="selector" @change="bindAppointTime($event, detail)">
							<view class="uni-input">{{detail.cAppointTime||'请选择'}}</view>
						</picker>
					</text>
				</view>
			</view>

			<picker @change="bindPickerChange" :value="cOrderPayType" :range="array">
				<view class="c-row b-b">


					<text class="tit">支付方式</text>
					<text class="icon-you"><text style="font-size: 26upx;">{{cOrderPayType}}</text><text
							class="yticon icon-you"></text></text>


				</view>
			</picker>



			<view class="c-row b-b" @click="chooseCoupon">
				<text class="tit">优惠券</text>

				<text class="icon-you"><text style="color: #f00;">-￥{{coupon.maxReduceAmount}}</text><text
						class="yticon icon-you"></text></text>
			</view>


			<view class="order-info">
				<view class="title">
					<text class="time">下单时间：{{detail.dConfirmDate}}</text>
				</view>
				<view class="detail">
					<view class="item">
						<text class="name">商品金额</text>
						<text class="desc">￥{{detail.fTotalMoney}}</text>
					</view>
					<view class="item">
						<text class="name">运费</text>
						<text class="desc">￥{{detail.iPostage+yun}}</text>
					</view>
					<!-- 	<view class="item">
						<text class="name">新人专享</text>
						<text class="desc">-￥10元</text>
					</view> -->
					<!-- <view class="item">
						<text class="name">优惠券</text>
						<text class="desc">无可用</text>
					</view> -->
					<view class="item">
						<text class="name">积分</text>
						<text class="desc">{{detail.iPointNum||0}}</text>
					</view>
				</view>
				<view class="total">
					<text class="all">应付合计</text>
					<text class="price">￥{{(detail.fTotalMoney*1000+yun*1000-coupon.maxReduceAmount*1000)/1000}}</text>
				</view>
			</view>
			<view class="service">
				<view class="title">
					<text>服务时间</text>
					<text class="time">8:30 -24:00</text>
				</view>
				<view class="contact">
					<view class="item" @click="link">
						<image src="/static/img/1/51.png" mode="aspectFill"></image>
						<text>在线客服</text>
					</view>
					<view class="item" @click="callPhone">
						<image src="/static/img/1/23.png" mode="aspectFill"></image>
						<text>电话客服</text>
					</view>
				</view>
			</view>

			<view class="footer-btn">
				<view class="left">
					<view class="checkall">
						应付&nbsp; ￥{{(detail.fTotalMoney*1000+yun*1000-coupon.maxReduceAmount*1000)/1000}}
					</view>
					<!-- <view class="freight">不含运费</view> -->
				</view>
				<view class="right">
					<view class="total"></view>
					<!-- 取消订单 -->
					<button :disabled="disa" class="settlement" @click="topay">结算</button>
				</view>
			</view>
		</view>
		<!-- 分享 -->
		<inputPopup ref="inputPopup" @setInput="setInput"></inputPopup>
	</view>
</template>

<script>
	import uniNumberBox from '@/components/uni-number-box.vue'
	import inputPopup from "@/components/uni-popup/inputPopup.vue"
	export default {
		components: {
			uniNumberBox,
			inputPopup
		},
		data() {

			return {
				empty: false, //空白页现实  true|false
				shareList: [],
				orderList: [],
				odeliveryType: [],
				detail: {
					fTotalMoney: 0,
					iPostage: 0,
					oCustomSetting: {
						isMerchantDistribution: 0,
						appointTime: ''
					}
				},
				addressData: {},
				disa: false,
				yun: 0,
				coupon: {
					maxReduceAmount: 0
				},
				cClientMemo: "限50个字",
				cOrderPayType: '',
				array: [],
				cDeliverName: "请选择",
				orderOtherData: {},
				cPayType: '',
				doubleClick: true,
				dlyFeeRuleId: [],
				postList: [],
				YUNPIGEC: 0, // 根据运费模板算出运费
				FzBigList: [],
				EMSList: [],
				STOresList: [], // 门店列表
				oMemeber: {}, // 买家信息
				appointTime: [],
				time: ''
			}
		},
		computed: {
			// // 获取时间开始时间（提货时间）
			// startDate() {
			// 	return this.getDate('start');
			// },
			// // 获取时间结束时间（提货时间）
			// endDate() {
			// 	return this.getDate('end');
			// }
		},
		watch: {
			"addressData": function() {
				let orderdata = []
				this.dlyFeeRuleId = []
				// this.detail.oOrderDetails.forEach(item=>{
				// 	this.dlyFeeRuleId.push(item.dlyFeeRuleId)
				// })
				for (let i in this.detail.orderDetailData) {
					if (this.detail.orderDetailData[i].cDeliverType == 'EMS') {
						orderdata.push({
							"iShopId": i,
							"data": {
								giftPreferItemId: '',
								oMemeber: this.detail.oMemeber,
								orderDetail: this.detail.orderDetailData[i].orderDetail,
								price: this.detail.orderDetailData[i].fTotalMoney,
								dlyTypeId: this.dlyFeeRuleId.join(',')
							}

						})
					}

				}

				let postactivity = {
					"addressId": this.addressData.id,
					"price": this.detail.fTotalMoney,
					"orderDetailData": orderdata
				}
				if (postactivity.orderDetailData.length > 0) {
					this.$Request.post(this.$api.httpApi.order.getPostActivityList + "&token=" + this.$SysCache
						.get('token'), {
							"param": postactivity
						}).then(resq => {
						let allyun = 0
						for (var s in resq.data) {
							if (s != -2) {
								allyun += resq.data[s].postPrice[res.data.iCorpId]
							}

						}
						// this.yun = resq.data[-2].postPrice[res.data.iCorpId]||resq.data[].postPrice[res.data.iCorpId]
						this.yun = allyun
						this.postList = resq.data
						// this.OrderGetStoreListData()
					})
				} else {
					this.yun = 0
					this.postList = []
					// this.OrderGetStoreListData()
				}

			},
			"cDeliverName": function() {
				if (this.cDeliverName == "门店自提") {
					this.yun = 0
				}
			}
		},
		onShow() {
			uni.hideLoading()

		},
		onLoad() {
			let datas = {
				"token": this.$SysCache.get('token') || null,
				"iSourceDetail": 1
			}
			this.$Request.post(this.$api.httpApi.order.getNewOrder + "&token=" + this.$SysCache.get('token'), datas).then(
				res => {
					if (res.code == 200) {
						this.appointTime = res.data.oCustomSetting.appointTime.split(';') || '00:00-23:59'


						console.log('获取购物车信息', res.data.oOrderDetails)
						// this.forShowId(res.data.orderDetailData) // 通过方法对订单商品进行分组
						this.orderList = res.data.oOrderDetails
						this.oMemeber = res.data.oMemeber, // 获取买家信息
						this.odeliveryType = res.data.odeliveryType
						for (let o in res.data.orderDetailData) {
							this.$set(res.data.orderDetailData[o], "cClientMemo", '')
						}
						if (res.data.oCustomSetting.isMerchantDistribution == 1) {
							for (let o in res.data.orderDetailData) {
								this.$set(res.data.orderDetailData[o], "cClientMemo", '')
								this.$set(res.data.orderDetailData[o], "number", 0)
								this.$set(res.data.orderDetailData[o], "storeNumber", 0)
								this.$set(res.data.orderDetailData[o], "storeName", '')
								this.$set(res.data.orderDetailData[o], "dAppointDate", this.getDates('start'))
								this.$set(res.data.orderDetailData[o], "cAppointTime", '')
								this.$set(res.data.orderDetailData[o], "timeNumber", 0)
								if(res.data.orderDetailData[o].cDeliverType == "EMS"){
									res.data.orderDetailData[o].cDeliverName = res.data.orderDetailData[o].cDeliverName!=''?res.data.orderDetailData[o].cDeliverName:res.data.orderDetailData[o].shopCustomSetting.emsShowName
									
								}else if(res.data.orderDetailData[o].cDeliverType == "PICKUP"){
									res.data.orderDetailData[o].cDeliverName = res.data.orderDetailData[o].cDeliverName!=''?res.data.orderDetailData[o].cDeliverName:res.data.orderDetailData[o].shopCustomSetting.pickupShowName
									
								}else if(res.data.orderDetailData[o].cDeliverType == "STOREDELIVERY"){
									res.data.orderDetailData[o].cDeliverName = res.data.orderDetailData[o].cDeliverName!=''?res.data.orderDetailData[o].cDeliverName:res.data.orderDetailData[o].shopCustomSetting.deliveryShowName
									
								}
							}
						} else {
							this.$set(res.data, "cClientMemo", '')
							this.$set(res.data, "number", 0)
							this.$set(res.data, "storeNumber", 0)
							this.$set(res.data, "storeName", '')
							this.$set(res.data, "dAppointDate", this.getDates('start'))
							this.$set(res.data, "cAppointTime", '')
							this.$set(res.data, "timeNumber", 0)
							for (let s in res.data.orderDetailData) {
								res.data.orderDetailData[s].cDeliverType =res.data.cDeliverType
								res.data.orderDetailData[s].cDeliverName =res.data.cDeliverName
							}
						}
						
						this.detail = res.data
						
						this.addressData.cReceiver = res.data.cReceiver
						this.addressData.cMobile = res.data.cReceiveMobile
						this.addressData.cAddress = res.data.cReceiveAddress
						this.addressData.id = res.data.iMemeberAddress
						this.addressData.cRegion = res.data.cRegion
						// this.cDeliverName = res.data.oDeliverTypeList[0].name
						// this.orderOtherData.cDeliverType = res.data.oDeliverTypeList[0].id
						// this.orderOtherData.cDeliverName = res.data.oDeliverTypeList[0].name
						// this.EMSList = res.data.oDeliverTypeList
						res.data.oPayType.forEach(item => {
							this.array.push(item.name)
							this.cOrderPayType = item.name
						})

						let orderdata = []
						this.dlyFeeRuleId = []
						// 获取运费
						// let Searchid = res.data.oOrderDetails[0].dlyFeeRuleId
						// let ContinueunitData = res.data.odeliveryType.find(function (obj) {
						// 	return obj.id === Searchid;//取出this.studentL里的id为1的那条数据所有的信息
						// })
						// console.log('获取运费', ContinueunitData)
						// this.yun = ContinueunitData.continueunit

						for (let i in this.detail.orderDetailData) {
							if (this.detail.orderDetailData[i].cDeliverType == 'EMS') {
								orderdata.push({
									"iShopId": i,
									"data": {
										giftPreferItemId: '',
										oMemeber: this.detail.oMemeber,
										orderDetail: this.detail.orderDetailData[i].orderDetail,
										price: this.detail.orderDetailData[i].fTotalMoney,
										dlyTypeId: this.detail.orderDetailData[i].dlyFeeRuleId
									}
								})
							}


						}
						let postactivity = {
							"addressId": res.data.iMemeberAddress,
							"price": res.data.fTotalMoney,
							"orderDetailData": orderdata
						}
						if (postactivity.orderDetailData.length > 0) {
							this.$Request.post(this.$api.httpApi.order.getPostActivityList + "&token=" + this.$SysCache
								.get('token'), {
									"param": postactivity
								}).then(resq => {
								let allyun = 0
								for (var s in resq.data) {
									if (s != -2) {
										allyun += resq.data[s].postPrice[res.data.iCorpId]
									} else {
										allyun = resq.data[-2].postPrice[res.data.iCorpId]
									}

								}
								// this.yun = resq.data[-2].postPrice[res.data.iCorpId]||resq.data[].postPrice[res.data.iCorpId]
								this.yun = allyun
								this.postList = resq.data
								// this.OrderGetStoreListData()
							})
						} else {
							this.yun = 0
							this.postList = []
							// this.OrderGetStoreListData()
						}

					}
				})
		},
		methods: {
			//获取配送方式
			getEms(item) {
			
				this.EMSList = []
				let ems = []
				if (this.detail.oCustomSetting.isMerchantDistribution == 0) {
					item.oOrderDetails.forEach(dd => {
						if (dd.oOrderDetailPropertys) {
							let ds = dd.oOrderDetailPropertys[0].promptMessage.split("|")
							ds.forEach(itemd => {
								if (itemd == "快递物流") {
									ems.push({
										id: "EMS",
										name: item.oCustomSetting.emsShowName||'快递物流'
									})
								} else if (itemd == "门店自提") {
									ems.push({
										id: "PICKUP",
										name: item.oCustomSetting.pickupShowName||'门店自提'
									})
								} else if (itemd == "门店配送") {
									ems.push({
										id: "STOREDELIVERY",
										name: item.oCustomSetting.deliveryShowName||'门店配送'
									})
								}
			
							})
						}
					})
			
			
					console.log(ems)
					if (ems.length > 0) {
						this.EMSList = ems
					} else {
						let tem = item.oCustomSetting.dlyType.split("AND")
						tem.forEach(itemd => {
							if (itemd == "EMS") {
								this.EMSList.push({
									id: "EMS",
									name: item.oCustomSetting.emsShowName||'快递物流'
								})
							} else if (itemd == "PICKUP") {
								this.EMSList.push({
									id: "PICKUP",
									name: item.oCustomSetting.pickupShowName||'门店自提'
								})
							} else if (itemd == "STOREDELIVERY") {
								this.EMSList.push({
									id: "STOREDELIVERY",
									name: item.shopCustomSetting.deliveryShowName||'门店配送'
								})
							}
			
						})
					}
				} else {
					item.orderDetail.forEach(dd => {
						if (dd.oOrderDetailPropertys) {
							let ds = dd.oOrderDetailPropertys[0].promptMessage.split("|")
							ds.forEach(itemd => {
								if (itemd == "快递物流") {
									ems.push({
										id: "EMS",
										name: item.shopCustomSetting.emsShowName||'快递物流'
									})
								} else if (itemd == "门店自提") {
									ems.push({
										id: "PICKUP",
										name: item.shopCustomSetting.pickupShowName||'门店自提'
									})
								} else if (itemd == "门店配送") {
									ems.push({
										id: "STOREDELIVERY",
										name: item.shopCustomSetting.deliveryShowName||'门店配送'
									})
								}
			
							})
						}
					})
			
			
					console.log(ems)
					if (ems.length > 0) {
						this.EMSList = ems
					} else {
						let tem = item.shopCustomSetting.dlyType.split("AND")
						console.log('tem'+tem)
						tem.forEach(itemd => {
							if (itemd == "EMS") {
								this.EMSList.push({
									id: "EMS",
									name: item.shopCustomSetting.emsShowName||'快递物流'
								})
							} else if (itemd == "PICKUP") {
								this.EMSList.push({
									id: "PICKUP",
									name: item.shopCustomSetting.pickupShowName||'门店自提'
								})
							} else if (itemd == "STOREDELIVERY") {
								this.EMSList.push({
									id: "STOREDELIVERY",
									name: item.shopCustomSetting.deliveryShowName||'门店配送'
								})
							}
			
						})
					}
				}
			
			
				this.EMSList.forEach((it, index) => {
					if (it.id == item.cDeliverType) {
						item.number = index
					}
				})
			
			},
			// 获取门店列表
			OrderGetStoreListData(item) {
				console.log('获取门店列表oMemeber', this.oMemeber)
				let params = {
					area: this.oMemeber.cAreaSrcArea,
					city: this.oMemeber.cAreaSrcCity,
					province: this.oMemeber.cAreaProvince,
					iShopId: this.detail.oCustomSetting.isMerchantDistribution == 1 ? item.shopCustomSetting.iShopId :
						item.oCustomSetting.iShopId
				}
				this.$Request.post(this.$api.httpApi.order.getStoreList + "&token=" + this.$SysCache.get('token'), params)
					.then(
						res => {
							if (res.code == 200) {
								console.log('获取门店列表', res.data)
								this.STOresList = res.data
							}
						}
					)
			},

			// 获取备输入
			bindTextAreaBlur(e, o) {
				console.log('a', e, o)
				o.cClientMemo = e.detail.value
			},
			// 提货时间确认
			bindDateChange(e, o) {
				console.log('时间选择', e, o)
				o.dAppointDate = e.target.value
			},
			// 预约时间起
			bindAppointTime(e, o) {
				console.log('预约时间起', e, o)
				if (this.detail.oCustomSetting.isMerchantDistribution == 1) {
					o.cAppointTime = (o.shopCustomSetting.appointTime.split(';'))[e.target.value]
				} else {
					o.cAppointTime = (o.oCustomSetting.appointTime.split(';'))[e.target.value]
				}

				o.timeNumber = e.target.value
			},
			// 选择门店
			bindSToreNameChange(e, o) {
				console.log('选择门店', e, o, this.STOresList)
				if (!isNaN(e.detail.value)) {
					o.storeName = this.STOresList[e.detail.value].name
					o.storeId = this.STOresList[e.detail.value].id
					o.storeNumber = e.detail.value
				} else {
					o.storeName = this.STOresList[0].name
				}
			},

			// 配送方式
			bindEMSChange(e, o) {
				console.log('', e, o)
				if (!isNaN(e.detail.value)) {
					o.cDeliverType = this.EMSList[e.detail.value].id
					o.cDeliverName = this.EMSList[e.detail.value].name
					o.number = e.detail.value
					console.log(o)
					if(this.detail.oCustomSetting.isMerchantDistribution == 0){
						for (let s in this.detail.orderDetailData) {
							this.detail.orderDetailData[s].cDeliverType = o.cDeliverType
							this.detail.orderDetailData[s].cDeliverName = o.cDeliverName
						}
					}
					this.getPost(o)
				} else {
					return false
				}
			},
			getPost(o) {
				let res = {
					data: this.detail
				}
				let orderdata = []
				this.dlyFeeRuleId = []
				// 获取运费
				// let Searchid = res.data.oOrderDetails[0].dlyFeeRuleId
				// let ContinueunitData = res.data.odeliveryType.find(function (obj) {
				// 	return obj.id === Searchid;//取出this.studentL里的id为1的那条数据所有的信息
				// })
				// console.log('获取运费', ContinueunitData)
				// this.yun = ContinueunitData.continueunit

				for (let i in this.detail.orderDetailData) {
					console.log(i)
					// if (i == o.shopCustomSetting.iShopId||o.oCustomSetting.iShopId) {
					// 	this.detail.orderDetailData[i].cDeliverType = o.dlyType
					// }

					if (this.detail.orderDetailData[i].cDeliverType == 'EMS') {
						orderdata.push({
							"iShopId": i,
							"data": {
								giftPreferItemId: '',
								oMemeber: this.detail.oMemeber,
								orderDetail: this.detail.orderDetailData[i].orderDetail,
								price: this.detail.orderDetailData[i].fTotalMoney,
								dlyTypeId: this.detail.orderDetailData[i].dlyFeeRuleId
							}
						})
					}


				}
				let postactivity = {
					"addressId": res.data.iMemeberAddress,
					"price": res.data.fTotalMoney,
					"orderDetailData": orderdata
				}
				if (postactivity.orderDetailData.length > 0) {
					this.$Request.post(this.$api.httpApi.order.getPostActivityList + "&token=" + this.$SysCache
						.get('token'), {
							"param": postactivity
						}).then(resq => {
						let allyun = 0
						for (var s in resq.data) {
							if (s != -2) {
								allyun += resq.data[s].postPrice[res.data.iCorpId]
							} else {
								// allyun = resq.data[-2].postPrice[res.data.iCorpId]
							}

						}
						// this.yun = resq.data[-2].postPrice[res.data.iCorpId]||resq.data[].postPrice[res.data.iCorpId]
						this.yun = allyun
						this.postList = resq.data
						// this.OrderGetStoreListData()
					})
				} else {
					this.yun = 0
					this.postList = []
					// this.OrderGetStoreListData()
				}

			},
			// 对订单数据进行分组
			async forShowId(forShowId) {
				let NewBigList = []
				console.log('对订单数据进行分组', forShowId)
				for (let i in forShowId) {
					// console.log(i)
					// let data = {
					// 	id: forShowId[i].iProductId,
					// 	iShopId: forShowId[i].iShopId,
					// }
					// let res = await this.$Request.post(this.$api.httpApi.goods.iteminfo + "&token=" + this.$SysCache
					// 	.get('token'), data)
					forShowId[i]["iShopId"] = i
					NewBigList.push(forShowId[i])
				}
				this.GrouPing(NewBigList) //  将合并后的数据去重分组，并添加所选的配送方式
			},
			//  将合并后的数据去重分组，并添加所选的配送方式
			GrouPing(GrouPingArray) {
				console.log('GrouPingArray', JSON.parse(JSON.stringify(GrouPingArray)))
				let arr = GrouPingArray
				let map = {}
				let dest = []
				for (let i = 0; i < arr.length; i++) {
					let AI = arr[i]
					// let ShopTatle = AI.ShopShow.cShopName // 店铺名称
					let iProductIdData = ''
					let ShopTatle = ''
					if (AI.shopCustomSetting === undefined) {
						ShopTatle = ''
						iProductIdData = ''
					} else {
						ShopTatle = AI.shopCustomSetting.cShopTag // 店铺名
						// iProductIdData = AI.iProductId
					}
					if (!map[ShopTatle]) {
						dest.push({
							ShopTatle: ShopTatle, // 店铺名
							GoodsShow: AI.orderDetail, // 店铺下的商品
							// iProductId: iProductIdData,
							// iProductId: AI.ShopShow.iCustId, // 店铺id
							dlyType: AI.cDeliverType, // 配送方式
							iSKUId: AI.iSKUId, // skuid
							iShopId: AI.iShopId, // 店铺id
							cDeliverName: AI.cDeliverName, // 配送方式名称
							cClientMemo: '', // 订单备注
							storeName: '请选择', // 门店名称
							dAppointDate: this.getDates('start'), // 提货时间/预约日期
							storeAddress: {
								province: '', // 省
								city: '', // 市
								area: '', // 区
							},
							shopCustomSetting: AI.shopCustomSetting,
							cAppointTime: (AI.shopCustomSetting.appointTime.split(";"))[0], // 预约时间段开始时间
							isHaveMutexStrategy: AI.isHaveMutexStrategy,
						});
						map[ShopTatle] = AI;
					} else {
						for (var j = 0; j < dest.length; j++) {
							var dj = dest[j];
							if (dj.ShopTatle == ShopTatle) {
								dj.GoodsShow.push(AI);
								break;
							}
						}
					}
				}
				this.FzBigList = dest
				console.log("FzBigList", this.FzBigList)
			},
			getDates(type, iAppointLimitDays) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					// year = year - 60;
				} else if (type === 'end') {
					day = day + (iAppointLimitDays - 1);
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				console.log(type, iAppointLimitDays)
				return `${year}-${month}-${day}`;
			},
			// 回显
			TheEcho(TheEcho) {
				console.log('TheEcho', TheEcho)
				console.log('配送方式', this.EMSList)
				let ems = this.detail.oDeliverTypeList
				for (var i = 0; i < ems.length; i++) {
					if (ems[i].id === TheEcho) {
						return ems[i].name; //不支持则进入循环,判断为真后输入
					}
				}
			},
			setInput(index, val) {
				this.$set(this.detail.orderDetailData[this.orderList[index].iShopId || -1], "cClientMemo", val)
				this.$set(this.orderList[index], "cClientMemo", val)

			},
			showInput(index, val) {
				console.log('输入备注', index, val)
				this.FzBigList[index].cClientMemo = val
				console.log('this.FzBigList', this.FzBigList)
				this.$refs.inputPopup.open(index, val)
			},
			chooseCoupon() {
				this.$SysCache.put('couponData', this.detail, 864000)
				uni.navigateTo({
					url: `/pages/coupon/index`
				})
			},
			numberChange() {

			},
			toStore() {
				uni.navigateTo({
					url: `/pages/order/store`
				})
			},
			setStore(item) {
				this.orderOtherData.storeName = item.name
				this.orderOtherData.storeId = item.id
				this.orderOtherData.storeAddress = {
					province: item.province,
					city: item.city,
					area: item.area
				}
			},
			add() {
				uni.navigateTo({
					url: `/pages/address/index`
				})
			},
			invoice() {
				uni.navigateTo({
					url: `/pages/invoice/add`
				})
			},
			topay() {
				this.disa = true;
				console.log(this.addressData)
				let token = this.$SysCache.get('token') || null
				this.detail.cReceiver = this.addressData.cReceiver
				this.detail.cReceiveMobile = this.addressData.cMobile
				this.detail.cReceiveAddress = this.addressData.cAddress
				this.detail.iMemeberAddress = this.addressData.id
				this.detail.cRegion = this.addressData.cRegion
				this.detail.couponFileId = this.coupon.couponId
				this.detail.couponId = this.coupon.couponCoding
				this.detail.couponId = this.coupon.couponCoding
				this.detail.couponTs = this.coupon.couponTs
				this.detail.cPayType = this.cPayType || this.detail.cOrderPayType
				
				if(this.detail.oCustomSetting.isMerchantDistribution == 0&&this.detail.cDeliverType!='EMS'){
					if(this.detail.storeId==0){
						uni.showToast({
							title:"请先选择门店！",
							icon:"none"
						})
						this.doubleClick = true
						this.disa = false
						return false
					}
				}
				if(this.detail.oCustomSetting.isMerchantDistribution == 1){
					for (let item in this.detail.orderDetailData) {
						if(this.detail.orderDetailData[item].cDeliverType!="EMS"&&this.detail.orderDetailData[item].storeId == 0){
							uni.showToast({
								title:"请先选择"+this.detail.orderDetailData[item].shopCustomSetting.cShopTag+"门店！",
								icon:"none"
							})
							this.doubleClick = true
							this.disa = false
							return false
						}
						
					}
				}
				
				// this.detail.cDeliverType = this.orderOtherData.cDeliverType
				// this.detail.cDeliverName = this.orderOtherData.cDeliverName
				// for (let item in this.detail.orderDetailData) {
				// 	this.detail.orderDetailData[item].cDeliverType = this.orderOtherData.cDeliverType
				// 	this.detail.orderDetailData[item].dAppointDate = this.orderOtherData.dAppointDate
				// 	this.detail.orderDetailData[item].cAppointTime = this.orderOtherData.cAppointTime
				// 	this.detail.orderDetailData[item].cReceiver = this.orderOtherData.cReceiver
				// 	this.detail.orderDetailData[item].cReceiveMobile = this.orderOtherData.cReceiveMobile
				// 	this.detail.orderDetailData[item].storeName = this.orderOtherData.storeName
				// 	this.detail.orderDetailData[item].storeId = this.orderOtherData.storeId
				// 	this.detail.orderDetailData[item].storeAddress = this.orderOtherData.storeAddress
				// 	this.detail.orderDetailData[item].cDeliverName = this.orderOtherData.cDeliverName
				// }
				// if (this.orderOtherData.cDeliverType == "PICKUP") {
				// 	this.detail.cDeliverType = this.orderOtherData.cDeliverType
				// 	this.detail.dAppointDate = this.orderOtherData.dAppointDate
				// 	this.detail.cAppointTime = this.orderOtherData.cAppointTime
				// 	this.detail.cReceiver = this.orderOtherData.cReceiver
				// 	this.detail.cReceiveMobile = this.orderOtherData.cReceiveMobile
				// 	this.detail.storeName = this.orderOtherData.storeName
				// 	this.detail.storeId = this.orderOtherData.storeId
				// 	this.detail.storeAddress = this.orderOtherData.storeAddress
				// 	this.detail.cDeliverName = this.orderOtherData.cDeliverName
				// }

				console.log(this.detail)

				if (this.doubleClick) {
					this.doubleClick = false
					console.log("33")
					this.$Request.post(this.$api.httpApi.order.submitOrder + "&token=" + this.$SysCache.get('token'), {
						"neworder": this.detail
					}).then(res => {
						this.disa = false;
						this.doubleClick = true
						if (res.code == 200) {
							this.payorder(res.data.cOrderNo)

						}
					})
				}


			},

			payorder(cOrderNo) {
				let that = this
				let paydata = {
					"cOrderNo": cOrderNo,
					"paytype": 1,
					"remark": "营家支付",
					"paytypecode": "construct",
					"payBackUrl": "/client/Pay/payNotify?paytypecode=construct",
				}
				this.$Request.post(this.$api.httpApi.order.buildPayment + "&token=" + this.$SysCache.get('token'), paydata)
					.then(
						res => {
							if (res.code == 200) {
								let typeData = ''
								let ua = window.navigator.userAgent.toLowerCase()
								// 通过正则表达式匹配ua中是否含有MicroMessenger字符串
								if (ua.match(/MicroMessenger/i) == 'micromessenger') {
									console.log('微信浏览器')
									typeData = "CASHIER_PAY_JSAPI" // 微信浏览器
								} else {
									// alert(uni.getStorageSync('TYPE'))
									if (uni.getStorageSync('TYPE') === '') {
										// alert("CASHIER_PAY_WAP")
										typeData = "CASHIER_PAY_WAP"
									} else {
										// alert("CASHIER_PAY_APP")
										typeData = "CASHIER_PAY_APP"
									}
									let isApp = true
									try {
										let postParam = {
											className: "BaseBridge",
											function: "getBaseInfo",
											successCallBack: "onSuccess",
											failCallBack: "onError"
										}
										HandBridge.postMessage(JSON.stringify(postParam));
									} catch (err) {
										console.log(err)
										isApp = false
									}
									if(isApp){
										typeData = "CASHIER_PAY_APP"
									}
								}
								let shop = []
								for (let item in this.detail.orderDetailData) {
									console.log('1111', this.postList, item, this.detail.orderDetailData[item].fTotalMoney)
									let data = {
										id: item,
										price: this.detail.orderDetailData[item].fTotalMoney,
										// postPrice: this.postList[item].postPrice[this.detail.iCorpId],
										postPrice: this.yun,
										// amount: (this.detail.orderDetailData[item].fTotalMoney * 1000 + this.postList[
										// 	item].postPrice[this.detail.iCorpId] * 1000) / 1000
										amount: (this.detail.orderDetailData[item].fTotalMoney * 1000 + this.yun *
											1000) / 1000
									}
									shop.push(data)
								}
								this.$Request.post4(
									this.$api.httpApi.user.pay, {
										"uid": this.$SysCache.get('userInfo').id || this.$SysCache.get('userInfo').mid,
										"pay_no": res.data.cPayNo,
										"token": this.$SysCache.get('token'),
										"order_no": res.data.cOrderNo,
										"shop": shop,
										// "page_url": `http://youyou.tangmu.xin/#/pages/order/success?cOrderNo=${res.data.cOrderNo}&type=1`,
										"page_url": `https://vip.inja.com/#/pages/order/success?cOrderNo=${cOrderNo}&type=1`,
										"amount": (this.detail.fTotalMoney * 1000 + this.yun * 1000 - this.coupon
											.maxReduceAmount * 1000) / 1000,
										"openId": this.$SysCache.get('openid') || null,
										"type": typeData

									}
								).then(res => {
									if (res.code == 1) {
										uni.showLoading({
											title: '正在跳转支付...'
										})
										let ur = this.urlEncode(res.data)
										let xx = ur.substr(0, 1)
										let yy = ur.replace(xx, '?')
										// console.log(yy)
										window.location.href =
										"https://ipay.inja.com/gateway/cashier/acquiring?dd=1" + ur //正式环境
										// window.location.href =
										// 	"http://ipay.ysyec.com/gateway/cashier/acquiring?dd=1" + ur //测试环境
										setTimeout(() => {
											uni.hideLoading()
										})

									} else {
										uni.hideLoading()
										uni.showToast({
											title: res.msg,
											icon: 'none'
										})
									}
								})
							}
						})
			},
			urlEncode(param, key, encode) {
				if (param == null) return '';
				var paramStr = '';
				var t = typeof(param);
				if (t == 'string' || t == 'number' || t == 'boolean') {
					paramStr += '&' + key + '=' + ((encode == null || encode) ? encodeURIComponent(param) : param);
				} else {
					for (var i in param) {
						var k = key == null ? i : key + (param instanceof Array ? '[' + i + ']' : '.' + i);
						paramStr += this.urlEncode(param[i], k, encode);
					}
				}
				return paramStr;
			},
			link() {
				window.location.href = 'https://yongyou-c7ca5f-8498.udesk.cn/im_client/?web_plugin_id=125391'
			},
			bindPickerChange(e) {
				console.log(e)
				this.cOrderPayType = this.detail.oPayType[e.target.value].name
				this.detail.oPayType.forEach(item => {
					if (item.name == this.cOrderPayType) {
						this.cPayType = item.id
					}
				})

			},
			// toDeliver() {
			// 	uni.navigateTo({
			// 		url: `/pages/order/deliver`
			// 	})
			// },
			setOrderData(item) {
				this.orderOtherData = item
				this.cDeliverName = item.cDeliverName
			},
			setremark(item) {
				this.cClientMemo = item
			},
			callPhone() {
				this.$Request.post(this.$api.httpApi.order.getContactWays + "&token=" + this.$SysCache.get('token')).then(
					res => {
						if (res.code == 200) {
							if (res.data.length > 0) {
								uni.makePhoneCall({
									phoneNumber: res.data[0].cContactNum //仅为示例
								});
							} else {
								uni.showToast({
									title: "请先设置电话客服",
									icon: "none"
								})
							}

						}
					})


			}
		},
		onNavigationBarButtonTap(e) {
			// console.log(e)

			// this.$refs.share.toggleMask();


		}


	}
</script>

<style lang="scss">
	page {
		background: #f5f5f5;
	}

	.car {

		.container {
			padding-bottom: 134upx;

			.c-row {
				display: flex;
				align-items: center;
				padding: 30upx 25upx;
				position: relative;
				background: #fff;
				margin-bottom: 10upx;

				.tit {
					width: 140upx;
					font-size: 30upx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: rgba(102, 102, 102, 1);

				}

				.icon-you {
					flex: 1;
					text-align: right;
					font-size: 26upx;
					color: #999;
					overflow: hidden;
					text-overflow: ellipsis;
					.uni-input{
						font-size: 26upx;
						padding: 0;
					}
				}

				>.icon-you {
					&::before {
						display: none;
					}
				}

			}

			.i-header {
				width: 100%;
				height: 10upx;
				display: block;
			}

			.address {
				padding: 28upx 23upx;
				height: 143upx;
				background: rgba(255, 255, 255, 1);
				box-shadow: 0upx 0upx 16upx 0upx rgba(0, 0, 0, 0.08);
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 10upx;

				.left {
					display: flex;
					height: 100%;
					align-items: center;
					justify-content: flex-start;
					flex-wrap: wrap;


					.name {
						display: inline-flex;
						width: 70%;
						justify-content: space-between;
						font-size: 30upx;
						font-family: Microsoft YaHei;
						font-weight: 400;
						color: rgba(51, 51, 51, 1);
						white-space: nowrap;
					}

					.addr {
						font-size: 30upx;
						font-family: Microsoft YaHei;
						font-weight: 400;
						color: rgba(51, 51, 51, 1);
						width: 100%;
					}
				}


				image {
					// flex: 1;
					display: flex;
					justify-content: flex-end;
					align-items: center;
					width: 46upx;
					height: 45upx;

				}

			}

			.car-list {
				width: 100%;
				// height:461px;
				background: rgba(255, 255, 255, 1);
				border-radius: 16upx;
				padding: 0 26upx;
				margin-bottom: 21upx;

				.title_name {
					font-size: 30upx;
					display: flex;
					height: 60upx;
					align-items: center;
					color: #f0406f;
				}

				.list-item {
					display: flex;
					justify-content: flex-start;
					align-items: center;

					.left {
						width: 34upx;
						margin-right: 24upx;

						image {
							width: 34upx;
							height: 34upx;
						}
					}

					.right {
						flex: 1;
						display: flex;
						justify-content: flex-start;
						align-items: center;
						padding: 32upx 0;
						border-bottom: 2upx solid #EBEBEB;

						.goods-img {
							width: 156upx;
							height: 156upx;
							background: rgba(255, 255, 255, 1);
							border: 1upx solid rgba(217, 217, 217, 1);
							opacity: 0.97;
							border-radius: 2upx;
							margin-right: 31upx;

							image {
								width: 156upx;
								height: 156upx;
							}
						}

						.info {
							flex: 1;
							height: 156upx;

							.name {
								display: flex;
								font-size: 26upx;
								font-family: Microsoft YaHei;
								font-weight: 400;
								color: rgba(0, 0, 0, 1);
								line-height: 20upx;
							}

							.price {
								display: flex;
								font-size: 33upx;
								font-family: Microsoft YaHei;
								font-weight: 400;
								color: rgba(240, 64, 111, 1);
							}

							.option {
								display: flex;
								font-size: 25upx;
								font-family: Microsoft YaHei;
								font-weight: 400;
								color: rgba(93, 93, 93, 1);
								justify-content: space-between;
								margin-top: 30upx;
							}
						}

					}

					&:last-child .right {
						border: none;
					}
				}

			}

			.order-info {
				padding: 6upx 25upx;
				background: #fff;
				margin-bottom: 10upx;

				.title {
					padding: 19upx 0;
					border-bottom: 2upx solid #f5f5f5;

					text {
						display: block;
						font-size: 26upx;
						font-family: Microsoft YaHei;
						font-weight: 400;
						color: rgba(102, 102, 102, 1);
						line-height: 40upx;
					}

				}

				.detail {
					padding: 26upx 0;
					border-bottom: 2upx solid #f5f5f5;

					.item {
						display: block;
						font-size: 28upx;
						font-family: Microsoft YaHei;
						font-weight: 400;
						color: rgba(102, 102, 102, 1);
						line-height: 40upx;

						.name {
							display: inline-block;
							width: 92upx;
							margin-right: 77upx;
							white-space: nowrap;
						}
					}
				}

				.total {
					padding: 33upx 0;
					font-size: 26upx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: rgba(240, 64, 111, 1);

					.all {
						display: inline-block;
						width: 92upx;
						margin-right: 55upx;
					}
				}
			}

			.service {
				padding: 35upx 25upx;
				background: #fff;

				.title {
					font-size: 28upx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: rgba(102, 102, 102, 1);

					.time {
						font-size: 24upx;
						font-family: Microsoft YaHei;
						font-weight: 400;
						color: rgba(102, 102, 102, 1);
						margin-left: 16upx;
					}
				}

				.contact {
					padding: 0;
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-top: 31upx;

					.item {
						width: 315upx;
						height: 74upx;
						background: rgba(255, 255, 255, 1);
						border: 1upx solid rgba(223, 223, 223, 1);
						border-radius: 5upx;
						font-size: 26upx;
						font-family: Microsoft YaHei;
						font-weight: 400;
						color: rgba(102, 102, 102, 1);
						display: flex;
						justify-content: center;
						align-items: center;

						image {
							width: 34upx;
							height: 36upx;
							margin-right: 15upx;
						}
					}
				}

			}
		}

		.footer-btn {
			position: fixed;
			/* left: 30upx; */
			bottom: 0;
			z-index: 95;
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 100%;
			height: 125upx;
			background: #1B1B1B;
			padding: 0 30upx;

			.left {
				width: 43%;
				height: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.checkall {
					font-size: 31upx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: rgba(255, 255, 255, 1);
					display: flex;
					align-items: center;
				}

				.freight {
					font-size: 22upx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: rgba(136, 136, 136, 1);
				}

			}

			.right {
				width: 57%;
				height: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.total {
					font-size: 33upx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: rgba(255, 255, 255, 1);
					white-space: nowrap;
					flex: 1;

					.price {
						font-size: 33upx;
						font-family: Microsoft YaHei;
						font-weight: 400;
						color: rgba(240, 64, 111, 1);
					}
				}

				.settlement {
					padding: 0 20upx;
					flex: 1;
					height: 58upx;
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 31upx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					background: rgba(240, 64, 111, 1);
					border-radius: 29upx;
					color: rgba(255, 255, 255, 1);
					white-space: nowrap;

				}
			}

		}
	}
</style>
